package elicecn.web.struts2ext.interceptor;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class ExceptionHandlerInterceptor implements Interceptor {
	private static final long serialVersionUID = 640452871558445298L;

	public static final String EXCEPTION_ATTRIBUTE = "exception";

	public static final String DEFAULT_RESULT = "system_error";

	public String intercept(ActionInvocation invocation) throws Exception {
		String result = null;
		try {
			result = invocation.invoke();
		} catch (Exception e) {
			e.printStackTrace();
			ServletActionContext.getRequest().setAttribute(EXCEPTION_ATTRIBUTE,
					e);
		}
		return result == null ? DEFAULT_RESULT : result;
	}

	public void destroy() {
	}

	public void init() {
	}
}
